package com.bywlkjs.bygo.wechat.applet.spring.boot.entity;

import com.alibaba.fastjson.JSON;
import com.bywlkjs.bygo.wechat.applet.config.WechatAppletConfig;
import com.bywlkjs.common.util.WebSentUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;

@Service
public class AuthCode2SessionEntity extends com.bywlkjs.bygo.wechat.applet.entity.AuthCode2SessionEntity implements Serializable {

    public static String REQUEST_URL="https://api.weixin.qq.com/sns/jscode2session";

    @Data
    @Accessors(chain = true)
    @NoArgsConstructor
    @Service
    public static class Result implements Serializable{

        @Resource
        private WechatAppletConfig wechatAppletConfig;

        public AuthCode2SessionEntity.Result analysis(Param param){
            param.setAppid(wechatAppletConfig.getAppid()).setSecret(wechatAppletConfig.getSecret());
            String result= WebSentUtil.sendGet(AuthCode2SessionEntity.REQUEST_URL,param);
            return JSON.parseObject(result, Result.class);
        }
    }

}
